Alpha-Beta Pruning

AlphaBetaPruning function from AIPlayForm.cs
int AlphaBetaPruning(int level, int alpha, int beta)
{
// limit
if (level == limit)
{
// AI
return evaluate(aiPlayer) - evaluate(userPlayer);
}
// MAX
if (level % 2 == 0)
{
// max
int max = -1000000;
// find 1
int find = 0;
//
for (int i = 0; i < edgeCount; i++)
{
for (int j = 0; j < edgeCount; j++)
{
//
if (board[i, j] == 0)
{
//
board[i, j] = aiPlayer;
//
int e = AlphaBetaPruning(level + 1, alpha, beta);
//
board[i, j] = 0;
//
if (max < e)
{
//
max = e;
if (level == 0)
{
targetX = i;
targetY = j;
}
}
// alpha
if (alpha < max)
{
alpha = max;
//
if (alpha >= beta) find = 1;
}
}
if (find == 1) break;
}
if (find == 1) break;
}
return max;
}
// MIN
else
{
// min
int min = 1000000;
// find 1
int find = 0;
//
for (int i = 0; i < edgeCount; i++)
{
for (int j = 0; j < edgeCount; j++)
{
//
if (board[i, j] == 0)
{
//
board[i, j] = userPlayer;
//
int e = AlphaBetaPruning(level + 1, alpha, beta);
//
board[i, j] = 0;
//
if (min > e) min = e;
// beta
if (beta > min)
{
beta = min;
//
if (alpha >= beta) find = 1;
}
}
if (find == 1) break;
}
if (find == 1) break;
}
return min;
}
}